import type {Graph} from "@/business/entity/graph/graph.entity";
import type {CircleGraph} from "@/business/entity/graph/circle.graph.entity";
import type {GraphService} from "@/business/interface/graph.interface";

/**
 *  绘制矩形实现类
 * @author JiangXincan
 * @date 2023/01/28 18:23
 */
export class RectangleGraphServiceImpl implements GraphService {
    create(ctx: CanvasRenderingContext2D, graph: Graph): void {
        ctx.fillRect(graph.center.centerX - graph.style.width / 2, graph.center.centerY - graph.style.height / 2, graph.style.width, graph.style.height);
    }
}

/**
 *  绘制圆形实现类
 * @author JiangXincan
 * @date 2023/01/28 18:23
 */
export class CircleGraphServiceImpl implements GraphService {
    create(ctx: CanvasRenderingContext2D, graph: Graph): void {
        ctx.arc(graph.center.centerX, graph.center.centerY, (<CircleGraph>graph).r, 0, Math.PI * 2);
    }
}

/**
 *  绘制椭圆形实现类
 * @author JiangXincan
 * @date 2023/01/28 18:23
 */
export class OvalGraphServiceImpl implements GraphService {
    create(ctx: CanvasRenderingContext2D, graph: Graph): void {
        ctx.ellipse(graph.center.centerX, graph.center.centerY, graph.style.width, graph.style.height, 0, 0, Math.PI * 2);
    }
}

/**
 *  绘制菱形实现类
 * @author JiangXincan
 * @date 2023/01/28 18:23
 */
export class DiamondGraphServiceImpl implements GraphService {
    create(ctx: CanvasRenderingContext2D, graph: Graph): void {
        ctx.moveTo(graph.center.centerX, graph.center.centerY);
        ctx.lineTo(graph.center.centerX + graph.style.width / 2, graph.center.centerY - graph.style.height / 2)
        ctx.lineTo(graph.center.centerX + graph.style.width, graph.center.centerY)
        ctx.lineTo(graph.center.centerX + graph.style.width / 2, graph.center.centerY + graph.style.height / 2)
    }
}


/**
 *  绘制图形代理对象
 * @author JiangXincan
 * @date 2023/01/28 18:23
 */

export const ProxyGraphServiceList = {
    "rectangleGraph": RectangleGraphServiceImpl,
    "circleGraph": CircleGraphServiceImpl,
    "ovalGraph": OvalGraphServiceImpl,
    "diamondGraph": DiamondGraphServiceImpl
};

// // interface ProxyService {
// type ProxyService = {
//     [id: string]: GraphService;
// }
//
// export const ProxyGraphServiceList = {
//     "rectangleGraph": new RectangleGraphServiceImpl(),
//     "circleGraph": new CircleGraphServiceImpl(),
//     "ovalGraph": new OvalGraphServiceImpl(),
//     "diamondGraph": new DiamondGraphServiceImpl()
// };